package com.ihrm.domain.system.vo;

import com.ihrm.domain.system.po.Permission;
import com.ihrm.domain.system.po.PermissionApi;
import com.ihrm.domain.system.po.PermissionMenu;
import com.ihrm.domain.system.po.PermissionPoint;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Getter
@Setter
@NoArgsConstructor
public class PermissionResult implements Serializable
{
    /**
     * 主键
     */
    private String id;
    /**
     * 权限名称
     */
    private String name;
    /**
     * 权限类型 1为菜单 2为功能 3为API
     */
    private Integer type;

    // 权限编码 用来表示权限
    private String code;

    /**
     * 权限描述
     */
    private String description;

    private String pid;

    private Integer enVisible;

    @OneToOne
    @JoinColumn(name = "id") // 这里的 id 是与 pe_permission_api 表的关联字段
    private Permission permission;
    @OneToOne
    @JoinColumn(name = "id") // 这里的 id 是与 pe_permission_api 表的关联字段
    private PermissionApi permissionApi;
    @OneToOne
    @JoinColumn(name = "id") // 这里的 id 是与 pe_permission_api 表的关联字段
    private PermissionPoint permissionPoint;
    @OneToOne
    @JoinColumn(name = "id") // 这里的 id 是与 pe_permission_api 表的关联字段
    private PermissionMenu permissionMenu;

    // 子节点
    private List<PermissionResult> childrenNode = new ArrayList<>();

    // 添加子权限的方法 1个的情况
    public void addChild(PermissionResult child) {
        this.childrenNode.add(child);
    }

    public PermissionResult(String id, String name, Integer type, String code, String description, String pid, Integer enVisible, PermissionApi permissionApi, PermissionPoint permissionPoint, PermissionMenu permissionMenu, Permission permission) {
        this.id = id;
        this.name = name;
        this.type = type;
        this.code = code;
        this.description = description;
        this.pid = pid;
        this.enVisible = enVisible;
        this.permissionApi = permissionApi;
        this.permissionPoint = permissionPoint;
        this.permissionMenu = permissionMenu;
        this.permission = permission;
    }

    @Override
    public String toString() {
        return "PermissionResult{" +
               "id='" + id + '\'' +
               ", name='" + name + '\'' +
               ", type=" + type +
               ", code='" + code + '\'' +
               ", description='" + description + '\'' +
               ", pid='" + pid + '\'' +
               ", enVisible=" + enVisible +
               ", permissionApi=" + permissionApi +
               ", permissionPoint=" + permissionPoint +
               ", permissionMenu=" + permissionMenu +
               ", childrenNode=" + childrenNode +
               '}';
    }
}
